'''
Created on 29.01.2011

@author: bstar
'''
from dopplershift.collector.http import REQUEST_METHOD_NONE
from dopplershift.core.containers.mediator import getMediator


class Condition:
    _request_method = REQUEST_METHOD_NONE
    _need_authenticate = False
    def __init__(self, template_name, request_method=REQUEST_METHOD_NONE, need_authenticate=False, content_type=None, renderer=None):
        self._need_authenticate = need_authenticate
        self._template_name = template_name
        self._request_method = request_method
        self._calls = []
        self._content_type = content_type
        self._renderer = renderer
        if self._content_type == None:
            self._content_type = 'text/html'
    def isCondition(self, auth_info=False, method=REQUEST_METHOD_NONE):
        if self._request_method != method:
            return False
        if self._need_authenticate == True and not auth_info:
            return False
        return True
    def putCall(self, callObj):
        self._calls.append(callObj)
    def getCalls(self):
        for el in self._calls:
            yield el
    def getContentType(self):
        return self._content_type
    def getTemplateName(self):
        return self._template_name
    def getRenderer(self):
        plugins_factory = getMediator().get("PluginsFactory")
        
        
        if self._renderer is None:
            default_renderer = getMediator().get("AppConfig").get("default_collector_renderer")
            renderer = plugins_factory.get(default_renderer, 'collector.renderer')
        else:
            renderer = plugins_factory.get(self._renderer, 'collector.renderer')
        return renderer